<template>
  <view class="progress" v-if="activityInfo">
	 
	 
    <view class="progress-container">
      <view class="status" v-for="(item,index) in timeline" :key="index" v-if="timeline">
		 <view class="progress-container-box">
			 <view style="text-align: center;padding-bottom: 48rpx;position: relative;" >
			 			<view class="status-text"  :class="[item.active  ?'active-progress':'']">
			 			  {{item.text}}
			 			</view>
			 			<view class="status-time"  :class="[item.active ?'active-progress':'',]">{{item.time.split('日')[0]}}日</view>
			 			<view class="status-time" :class="[item.active ?'active-progress':'']">{{item.time.split('日')[1].slice(0,5) }}</view> 
						<view  v-if="item.active && activeNum==index" class="isactive"></view>
			 </view> 
			 <view style="width: 72rpx;text-align: center;height: 40rpx;
    line-height: 40rpx;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;" v-if="index<timeline.length-1">
			   <image :src="item.active ? item.aicon:item.dicon" style="width: 24rpx;height: 10rpx;"></image>
			 </view>
		 </view> 
		 
      </view>
    </view>	 
	
  </view>
</template>

<script>
  export default {
    data() {
      return {
		  activeNum:null,
        timeline: [{
            text: '登记抽选',
            aicon: 'https://100000063-1252208446.file.myqcloud.com/images/MF-EB-P4/Step Items.png',
            dicon: 'https://100000063-1252208446.file.myqcloud.com/images/MF-EB-P4/Vector.png',
            time: '8月01日10:00:00',
            active: false,
            percent: 10
          },
          {
            text: '登记结束',
            aicon: 'https://100000063-1252208446.file.myqcloud.com/images/MF-EB-P4/Step Items.png',
            dicon: 'https://100000063-1252208446.file.myqcloud.com/images/MF-EB-P4/Vector.png',
            time: '8月01日13:00:00',
            active: false,
            percent: 36
          },
          {
            text: '获资购买',
            aicon: 'https://100000063-1252208446.file.myqcloud.com/images/MF-EB-P4/Step Items.png',
            dicon: 'https://100000063-1252208446.file.myqcloud.com/images/MF-EB-P4/Vector.png',
            time: '8月01日16:00:00',
            active: false,
            percent: 62
          },
          {
            text: '活动结束',
            aicon: 'https://100000063-1252208446.file.myqcloud.com/images/MF-EB-P4/Step Items.png',
            dicon: 'https://100000063-1252208446.file.myqcloud.com/images/MF-EB-P4/Vector.png',
            time: '8月01日10:00:00',
            active: false,
            percent: 88
          },
        ],
        percent: 0,
        activityDetail: {},
        progressDisable: false,
        timeCalculate: ''
      }
    },
    props: {
      exTime: {
        type: Object,
      },
      activityInfo: {
        type: Object,
      },
    },
    watch: {
    },
    mounted() {
      if (this.activityInfo && this.exTime) {
        this.getDeafaultStatus(this.activityInfo)
      }
    },
    methods: {
      getDeafaultStatus(info) {
        this.timeline[0].time = this.formatDate(info.activitySelectionStartTime)
        this.timeline[1].time = this.formatDate(info.activitySelectionEndTime)
        this.timeline[2].time = this.formatDate(info.promulgateTime)
        this.timeline[3].time = this.formatDate(info.buyEndTime)
        this.timeCalculate = setInterval(() => {
          this.controlProgress()
        }, 1000);

      },
      clearTime() {
        clearInterval(this.timeCalculate)
      },
      controlProgress() {
        let step, nowPercent, activeNum;
        let nowTime = new Date().getTime();
        let {
          exCreateTime,
          exStartTime,
          exEndTime,
          expromulgateTime,
          buyEndTime,
          activityStopTime
        } = this.exTime
        if (nowTime < exStartTime) {
          // step = (exStartTime - exCreateTime) / 10
          // nowPercent = (nowTime - exCreateTime) / step
          // this.percent = nowPercent
        } else if (nowTime > exStartTime && nowTime < exEndTime) {
          step = (exEndTime - exStartTime) / 26
          nowPercent = (nowTime - exStartTime) / step
          this.percent = nowPercent + 10
          activeNum = 0
        } else if (nowTime > exEndTime && nowTime < expromulgateTime) {
          step = (expromulgateTime - exEndTime) / 26
          nowPercent = (nowTime - exEndTime) / step
          this.percent = nowPercent + 36
          activeNum = 1
        } else if (nowTime > expromulgateTime && nowTime < buyEndTime) {
          step = (buyEndTime - expromulgateTime) / 26
          nowPercent = (nowTime - expromulgateTime) / step
          this.percent = nowPercent + 62
          activeNum = 2
        } else if (nowTime > buyEndTime) {
          this.progressDisable = true
          this.clearTime()
          activeNum = 3
        }
		this.activeNum = activeNum
        this.timeline.map((item, index) => {
          if (index <= activeNum) {
            item.active = true
          }
        })
      },
      formatDate(date) {
        let data = date.slice(5, 10).replace('-', '月') + '日' + date.slice(11, 19)
        let month = data.substring(0, 2)
        if (month < 10) {
          data = data.slice(1)
        }
        return data
      },
    }
  }
</script>

<style lang="scss">
  .progress,
  .progress-container {
    position: relative;
    width: 100%;
    // height: 124rpx;
    // overflow: hidden;
  }
  
  
 

  .progress-container {
    display: flex;
    justify-content: space-between;
    z-index: 2;
	
	.progress-container-box{
		box-sizing: border-box;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: flex-start;
		z-index: 2;
		
		.isactive {
			position: absolute;
			left:0;
			bottom:-2rpx;
			width: 100%;
			height:4rpx;
			background-color: #CB171A;
			// border-width: 0 0 4rpx 0;
			// border-style: solid;
			// border-color: #CB171A;
		}
	}

    .status {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      text-align: center;
	
      .status-text {
		font-family: 'NotoSansSC-Medium';
		font-size: 24rpx;
		height: 40rpx;
		line-height: 40rpx;
          color: #C6C6C6;
      
        &.active-progress {
          color: #000000;
        }
      }

      .status-time {
		  	font-family: 'FrankNew-Regular';
		font-size: 24rpx;
		margin-top: 8rpx;
        color: #333;
		height: 40rpx;
		line-height: 40rpx;
		  color: #C6C6C6;
		
		&.active-progress {
		  color: #757575;
		}
		
      }

      .macallan-icon {
        border-radius: 50%;
        background-color: #862633;
        color: #fff;
        width: 28rpx;
        height: 28rpx;
        font-size: 16rpx;
        text-align: center;
        line-height: 28rpx;

        // opacity: 0.4;
        image {
          width: 100%;
          height: 100%;
          display: block;
        }
      }
    }
  }

  .linebox {
    position: absolute;
    top: 50%;
    width: 100%;
    z-index: 1;

    .line {
      position: absolute;
      top: 1px;
      width: 100%;
      height: 1.5px;
      border-radius: 1px;
      background-color: #DBDBDB;
    }

    .active-line {
      position: absolute;
      z-index: 2;
      height: 3px;
      border-radius: 1px;

      &.disable-line {
        width: 100% !important;
      }

      .line-item {
        width: 100%;
        height: 100%;
        border-radius: 10px;
        // background-image: linear-gradient(-75deg, rgba(255, 255, 255, 0.6) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0.6) 75%, transparent 75%, transparent);
        background: linear-gradient(-48deg, #BC9597 40%, #862633 0, #862633 50%, #BC9597 0, #BC9597 60%, #862633 0);
        background-size: 16px 16px;
        animation: progress-bar-stripes 1s linear infinite;

        &.disable {
          background: linear-gradient(-48deg, #A9A9A9 40%, #818282 0, #818282 50%, #A9A9A9 0, #A9A9A9 60%, #818282 0);
          background-size: 16px 16px;
          animation: none;
        }
      }
    }

    @keyframes progress-bar-stripes {
      from {
        background-position: 0px 0
      }

      to {
        background-position: 16px 0
      }

    }

  }
</style>
